const Mock = require('mockjs');

const goodsInCart = [];

function addCartItems() {
  for (let i = 0; i < 5; i++) {
    goodsInCart.unshift(
      Mock.mock({
        id: "@id()",
        count: "@integer(1,10)",
        price: "@float(10,99,2,2)",
        title: "@cparagraph(1)",
        desc: "@cparagraph(3)",
        cover: "@dataImage('200x200')"
      })
    );
  }
}
addCartItems();

Mock.mock('/mock/cart', 'get', function () {
  if (goodsInCart) {
    return {
      code: 200,
      msg: '获取商品列表成功',
      data: goodsInCart
    }
  } else {
    return {
      code: 400,
      msg: '获取商品列表失败',
      data: []
    }
  }
});
